#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Instruments/TypePayoff.h>
#pragma unmanaged 
#include <ql\instruments\payoffs.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

#undef HANDLE
#define ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IStrikedTypePayoff
	public ref class CStrikedTypePayoff : 
            public CTypePayoff,
            public Cephei::QL::Instruments::IStrikedTypePayoff
	{
	protected: 
		boost::shared_ptr<QuantLib::StrikedTypePayoff>* _ppStrikedTypePayoff;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::StrikedTypePayoff>* _phStrikedTypePayoff;
#endif
		Object^ _StrikedTypePayoffOwner;     // reference to object that manages the storage for this object
	internal:
        CStrikedTypePayoff (boost::shared_ptr<QuantLib::StrikedTypePayoff>& childNative, Object^ owner);
        CStrikedTypePayoff (QuantLib::StrikedTypePayoff& childNative, Object^ owner);
        CStrikedTypePayoff (CStrikedTypePayoff^ copy);
        CStrikedTypePayoff (System::Type^ t);
#ifdef STRUCT
        CStrikedTypePayoff (QuantLib::StrikedTypePayoff childNative);
#endif       
#ifdef HANDLE
		CStrikedTypePayoff (QuantLib::Handle<QuantLib::StrikedTypePayoff>& childNative, Object^ owner);
		CStrikedTypePayoff (QuantLib::Handle<QuantLib::StrikedTypePayoff> childNative);
#endif
		virtual ~CStrikedTypePayoff ();
		!CStrikedTypePayoff ();

	internal:
		QuantLib::StrikedTypePayoff& GetReference ();
		boost::shared_ptr<QuantLib::StrikedTypePayoff>& GetShared ();
		QuantLib::StrikedTypePayoff* GetPointer ();
        void SetStrikedTypePayoff (boost::shared_ptr<QuantLib::StrikedTypePayoff> native)
        {
            if (_ppStrikedTypePayoff != NULL)
                delete _ppStrikedTypePayoff;
            _ppStrikedTypePayoff = new boost::shared_ptr<QuantLib::StrikedTypePayoff> (native);
            SetTypePayoff (boost::dynamic_pointer_cast<QuantLib::TypePayoff> (*_ppStrikedTypePayoff));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::StrikedTypePayoff>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property String^ Description 
        {
		    virtual String^ get () ;
        }
        property Double Strike 
        {
		    virtual Double get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IStrikedTypePayoff Vector interface
	ref class CStrikedTypePayoffVector : public System::MarshalByRefObject,  
							    public INativeVector<IStrikedTypePayoff^>,
							    public INativeVector<Generic::ICell<IStrikedTypePayoff^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::StrikedTypePayoff>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::StrikedTypePayoff>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::StrikedTypePayoff>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CStrikedTypePayoffVector ();
#ifdef STRUCT
		CStrikedTypePayoffVector (std::vector<QuantLib::StrikedTypePayoff>& vec, Object^ owner);
		CStrikedTypePayoffVector (std::vector<QuantLib::StrikedTypePayoff> vec);
#endif       
		CStrikedTypePayoffVector (std::vector<boost::shared_ptr<QuantLib::StrikedTypePayoff>>& vec, Object^ owner);
#ifdef HANDLE
		CStrikedTypePayoffVector (std::vector<QuantLib::Handle<QuantLib::StrikedTypePayoff>>& vec, Object^ owner);
#endif
		virtual ~CStrikedTypePayoffVector ();
		!CStrikedTypePayoffVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IStrikedTypePayoff^ default[int] 
		{
			virtual IStrikedTypePayoff^ get (int index) = INativeVector<IStrikedTypePayoff^>::default::get;
			virtual void set (int index, IStrikedTypePayoff^ value) = INativeVector<IStrikedTypePayoff^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Generic::ICell<Cephei::QL::Instruments::IStrikedTypePayoff^>^ CItem[int] 
		{
			virtual Generic::ICell<IStrikedTypePayoff^>^ get (int index) = INativeVector<Generic::ICell<IStrikedTypePayoff^>^>::default::get;
			virtual void set (int index, Generic::ICell<IStrikedTypePayoff^>^ value) = INativeVector<Generic::ICell<IStrikedTypePayoff^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::StrikedTypePayoff>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::StrikedTypePayoff>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::StrikedTypePayoff>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CStrikedTypePayoff_Factory : public System::MarshalByRefObject,  public IStrikedTypePayoff_Factory
	{
	public:
        /* <summary> Create a hybrid Vector of IStrikedTypePayoff, with event notification of changes </summary> */
        virtual Cephei::IVector<IStrikedTypePayoff^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IStrikedTypePayoff, with event notification of changes </summary> */
        virtual Generic::ICell<Cephei::IVector<Generic::ICell<IStrikedTypePayoff^>^>^>^ CreateCellVector();
        virtual Cephei::IVector<IStrikedTypePayoff^>^ CreateVector(System::Collections::Generic::IEnumerable<IStrikedTypePayoff^>^ source);
        virtual Generic::ICell<Cephei::IVector<Generic::ICell<IStrikedTypePayoff^>^>^>^ CreateCellVector(System::Collections::Generic::IEnumerable<Generic::ICell<IStrikedTypePayoff^>^>^ source);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
